import 'package:duqin/pages/root_pages/home_page.dart';
import 'package:duqin/pages/root_pages/me_page.dart';
import 'package:duqin/pages/root_pages/music_page.dart';
import 'package:duqin/pages/root_pages/video_page.dart';
import 'package:flutter/material.dart';

class RootPage extends StatefulWidget {
  const RootPage({Key? key}) : super(key: key);

  @override
  _RootPageState createState() => _RootPageState();
}

class _RootPageState extends State<RootPage> {
  int _currentIndex = 0;
// 导航栏页面
  final List<Widget> _pages = [
    HomePage(),
    MusicPage(),
    Container(),
    VideoPage(),
    MePage()
  ];
  // 底部导航栏
  final List<BottomNavigationBarItem> _listBar = [
    BottomNavigationBarItem(icon: Icon(Icons.home), label: '首页'),
    BottomNavigationBarItem(icon: Icon(Icons.my_library_music), label: '音乐'),
    BottomNavigationBarItem(icon: Icon(Icons.add), label: ''),
    BottomNavigationBarItem(icon: Icon(Icons.voicemail_outlined), label: '小视频'),
    BottomNavigationBarItem(icon: Icon(Icons.my_location), label: '我的'),
  ];

  @override
  Widget build(BuildContext context) {
    return Scaffold(
      bottomNavigationBar: BottomNavigationBar(
        items: _listBar,
        currentIndex: _currentIndex,
        onTap: _bottomNavigatClick,
        type: BottomNavigationBarType.fixed,
      ),
      floatingActionButton: FloatingActionButton(
          //悬浮按钮
          child: Icon(Icons.add),
          onPressed: _onAdd),
      floatingActionButtonLocation: FloatingActionButtonLocation.centerDocked,
      body: IndexedStack(
        index: _currentIndex,
        children: _pages,
      ),
    );
  }

  // 底部导航栏切换
  void _bottomNavigatClick(int value) {
    if (value == 2) {
      return _onAdd();
    }
    setState(() {
      _currentIndex = value;
    });
  }

  //中部添加按钮
  void _onAdd() {
    print('点击中部添加按钮');
  }
}
